package com.tempjob.admin.controller;

import com.tempjob.admin.dto.JobCategoryModifyDTO;
import com.tempjob.admin.security.annotation.AdminLogAnnotation;
import com.tempjob.common.businesss.mongo.entity.JobCategory;
import com.tempjob.common.businesss.service.MongoBeanUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @author hui
 * @Date 2022/12/29 10:37
 **/

@RequestMapping("/sys/job")
@RestController
@Api(tags = "工作管理")
@CrossOrigin(originPatterns = "*", methods = {RequestMethod.GET, RequestMethod.POST})
public class JobController {

    @Autowired
    private MongoBeanUtil mongoBeanUtil;

    @GetMapping("categoryTree")
    @ApiOperation(value = "获取工作分类树形")
    @AdminLogAnnotation(title = "工作管理", action = "categoryTree")
    public Object categoryTree() {
        List<JobCategory> allList = mongoBeanUtil.getJobCategoryService().list();
        return mongoBeanUtil.getJobCategoryService().buildTree(allList);
    }

    @PostMapping("/modifyCategory")
    @ApiOperation(value = "新增或更新工作分类")
    @AdminLogAnnotation(title = "工作管理", action = "新增或更新工作分类")
    public Object modifyCategory(@RequestBody @Valid JobCategoryModifyDTO dto) {
        JobCategory category = new JobCategory();
        if (dto.getId() == null) {
            category = mongoBeanUtil.getJobCategoryService().getById(dto.getId());
        }
        category.setCategoryName(dto.getCategoryName());
        category.setParentId(dto.getParentId());
        return mongoBeanUtil.getJobCategoryService().saveOrUpdate(category);
    }

//    @ApiOperation(response = JobListVO.class, value = "工作列表", notes = "")
//    @PostMapping(value = "/jobList")
//    @Transactional
//    @AdminLogAnnotation(title = "工作信息", action = "工作列表")
//    public Object jobList(@RequestBody JobListDTO dto) {
//        PageParam page = new PageParam(dto.getPage(), dto.getSize());
//        LambdaQueryChainWrapper queryWrapper = mongoBeanUtil.getJobInfoService().lambdaQuery();
//        if (StringUtils.isNotBlank(dto.getOrder()) && StringUtils.isNotBlank(dto.getSort())) {
//            if (dto.getSort().equalsIgnoreCase("asc")) {
//                queryWrapper.orderByAsc(dto.getOrder());
//            } else {
//                queryWrapper.orderByDesc(dto.getOrder());
//            }
//        } else {
//            queryWrapper.orderByDesc("update_time");
//        }
//        queryWrapper.eq("job_status", 2);
//        queryWrapper.eq(dto.getJobType() != null, "job_type", dto.getJobType());
//        queryWrapper.eq(dto.getJobCategory() != null, "job_category", dto.getJobCategory());
//        queryWrapper.eq(dto.getSettlementType() != null, "settlement_type", dto.getSettlementType());
//        queryWrapper.eq(dto.getPublishNature() != null, "publish_nature", dto.getPublishNature());
//        queryWrapper.like(StringUtils.isNoneBlank(dto.getJobTitle()), "job_title", dto.getJobTitle());
//        queryWrapper.like(StringUtils.isNoneBlank(dto.getJobAddress()), "job_address", dto.getJobAddress());
//        if (StringUtils.isNotBlank(dto.getCompanyName())) {
//            List<String> companyIds = mongoBeanUtil.getCompanyInfoService().lambdaQuery().like(CompanyInfo::getCompanyName, dto.getCompanyName()).list().stream().map(CompanyInfo::getId).collect(Collectors.toList());
//            if (companyIds == null || companyIds.isEmpty()) {
//                return page;
//            }
//            queryWrapper.in("company_id", companyIds);
//        }
//        if (StringUtils.isNotBlank(dto.getIndividualName())) {
//            List<String> individualIds = mongoBeanUtil.getIndividualInfoService().lambdaQuery().like(IndividualInfo::getIndividualName, dto.getIndividualName()).list().stream().map(IndividualInfo::getId).collect(Collectors.toList());
//            if (individualIds == null || individualIds.isEmpty()) {
//                return page;
//            }
//            queryWrapper.in("individual_id", individualIds);
//        }
//        return mongoBeanUtil.getJobInfoService().page(queryWrapper, page);
//    }

}
